package main

import (
	"fmt"
	"strconv"
)

func main() {
	str := "abc\nabc"
	fmt.Println(str)

	str1 := `package strdemo
			import "fmt"`
	fmt.Println(str1)

	fmt.Println("===========字符串拼接=========")

	var str5 = "hello" + "world"
	str5 += " haha"

	fmt.Println(str5)

	var str3 = "hello" +
		"world" + " hello"
	fmt.Println(str3)

	fmt.Println("===========基本数据类型转换========")
	var i int = 100
	var f1 float32 = float32(i)
	fmt.Println(f1)
	var f2 float64 = float64(f1)
	fmt.Println("f2=", f2)

	var i8 = int8(10)
	var i32 int32
	var i64 int64
	i32 = int32(i8) + 20
	i64 = int64(i32) + 10
	fmt.Println(i64)

	fmt.Println("===========基本数据类型和string转换========")
	// Sprintf根据format参数生成格式化的字符串并返回该字符串。
	var num1 int = 99
	var num2 float64 = 23.45
	var num3 bool = true
	var num4 byte = 'h'
	var str2 string
	str2 = fmt.Sprintf("%d", num1)
	fmt.Printf("str2 type %T str2=%v\n", str2, str2)

	str2 = fmt.Sprintf("%f", num2)
	fmt.Printf("str2 type %T str2=%v\n", str2, str2)

	str2 = fmt.Sprintf("%t", num3)
	fmt.Printf("str2 type %T str2=%v\n", str2, str2)

	str2 = fmt.Sprintf("%c", num4)
	fmt.Printf("str2 type %T str2=%v\n", str2, str2)

	fmt.Println("===========第二种方式转换========")

	str2 = strconv.FormatInt(int64(num1), 10)
	fmt.Printf("str2 type %T str2=%v\n", str2, str2)

	str2 = strconv.FormatFloat(num2, 'f', 10, 64)
	fmt.Printf("str2 type %T str2=%v\n", str2, str2)

	str2 = strconv.FormatBool(num3)
	fmt.Printf("str2 type %T str2=%v\n", str2, str2)

	var num5 = 4567

	str2 = strconv.Itoa(int(num5))
	fmt.Printf("str2 type %T str2=%v\n", str2, str2)

	fmt.Println("===========string转换为基本数据类型========")
	var str6 string = "true"
	var str7 string = "64"
	var str8 string = "64.543"
	var b, _ = strconv.ParseBool(str6)
	fmt.Printf("b type %T b=%v\n", b, b)

	var int10, _ = strconv.ParseInt(str7, 10, 64)
	fmt.Printf("int10 type %T int10=%v\n", int10, int10)

	var f10, _ = strconv.ParseFloat(str8, 64)
	fmt.Printf("f10 type %T f10=%v\n", f10, f10)

	var str9 string = "hello"
	var i11 int64
	i11, _ = strconv.ParseInt(str9, 10, 32)
	fmt.Printf("i11 type %T i11=%v\n", i11, i11)
}
